<template>
	<view class="page">
		<hx-navbar title=" " :fixed="true" bar-placeholder="hidden" transparent="hidden" :background-color="[74, 192, 255]" color="#ffffff"/>
		<image class="share_canvas" :style="{'margin-top':statusBarHeight+15+'px'}" :src="imgPrefix(img)" mode="widthFix"></image>
		<view class="btns dis-flex flex-y-center">
			<view class="btn_view t-c">
				<image class="save_btn" :src="imgPrefix('/static/image/icon/save_btn.png')"></image>
				<text>分享微信好友</text>
				<button class="share-btn" open-type="share">分享</button>
			</view>
			<view @tap="saveImageToPhotosAlbum(imgPrefix(img))" class="btn_view t-c">
				<image class="save_btn" :src="imgPrefix('/static/image/icon/save_btn.png')"></image>
				<text>保存到手机</text>
			</view>
		</view>
	</view>
</template>

<script>
const app = getApp();
import { statusBarHeight } from '@/static/mixins/statusBarHeight.js';
import API from '@/static/api/index.js';
export default {
	mixins: [statusBarHeight],
	data() {
		return {
			img:'/static/image/share_img.png'
		};
	},
	methods:{
		  saveImageToPhotosAlbum(img) {
			 app._log(img)
		    let that = this
			uni.getImageInfo({
				src:img,
				success: (res) => {
					uni.saveImageToPhotosAlbum({
					  filePath: res.path,
					  success: function(data) {
						  app._log(data)
							uni.showModal({
							  title: '图片保存成功',
							  content: '图片成功保存到相册了，去发圈噻~',
							  showCancel: false,
							  confirmText: '好哒',
							  confirmColor: '#72B9C3'
							})
					  },
					  fail: function(err) {
						  app._log(err)
					    if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
					      uni.showModal({
					        title: '提示',
					        content: '需要获取权限才能保存到相册',
					        success(res) {
					          if (res.confirm) {
					            uni.openSetting({
					              success(settingdata) {
					                if (settingdata.authSetting['scope.writePhotosAlbum']) {
					                  uni.showToast({ title: '获取权限成功'})
					                  app._log('获取权限成功，给出再次点击图片保存到相册的提示。')
					                } else {
					                  uni.showModal({
					                    title: '提示',
					                    content: '没有权限，人家很难给你保存到相册',
					                    showCancel: false,
					                    confirmText: '好的',
					                    confirmColor: '#72B9C3',
					                    success: function(res) {}
					                  })
					                  app._log('获取权限失败，给出不给权限就无法正常使用的提示')
					                }
					              }
					            })
					          } else if (res.cancel) {
					            // app._log('用户点击取消')
					          }
					        }
					      })
					    }
					  }
					})
				}
			})
		  }
	},
	onShareAppMessage(res) {
		if (res.from === 'button') {// 来自页面内分享按钮
			app._log(res.target)
		}
		return {
			title: '可语小程序',
			imageUrl:this.imgPrefix('/static/image/share_cover.png'),
			path: '/pages/teacher/login_identity/index'
		}
	}
};
</script>
<style lang="scss">
.page {
	background-color: #4AC0FF;
	background-image: linear-gradient(313deg, 
			#4AC0FF 0%, 
			#7F4AFF 40%, 
			#F4A3FF 100%);
	padding-top: 24rpx;
	padding-bottom: 0;
	min-height: 100vh!important;
}
.share_canvas {
	width: 654rpx;
	height: 1118rpx;
	margin: 0 48rpx;
}

.btns{
	justify-content: space-around;
	padding-top: 48rpx;
	.btn_view{
		position: relative;
	}
}
.save_btn{
	width: 80rpx;
	height: 80rpx;
	
}
text{
	display: block;
	font-size: 24rpx;
	text-align: center;
	color: #fff;
}
</style>
